package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.FeedbackPerson;
import com.huilai.platform.country_platform.model.PartyActivities;
import com.huilai.platform.country_platform.model.VillageActivities;
import com.huilai.platform.country_platform.model.VillageCommittee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/3/5
 * 注释：
 */
public interface VillageActivitiesReposity extends JpaRepository<VillageActivities, Integer>, JpaSpecificationExecutor<VillageActivities> {
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into village_activities(image, title, `describe`, file, content_type)" +
            "values(:#{#villageActivities.image},:#{#villageActivities.title},:#{#villageActivities.describe},:#{#villageActivities.file},:#{#villageActivities.contentType})", nativeQuery = true)
    Integer addVillageActivities(VillageActivities villageActivities);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update village_activities va set va.image = :#{#villageActivities.image}, " +
            "va.title = :#{#villageActivities.title}, " +
            "va.describe = :#{#villageActivities.describe}, " +
            "va.file = :#{#villageActivities.file}, " +
            "va.content_type = :#{#villageActivities.contentType} where va.id = :#{#villageActivities.id}",nativeQuery = true)
    Integer updateVillageActivities(VillageActivities villageActivities);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete from VillageActivities va where va.id = :id")
    Integer deleteVillageActivitiesById(Integer id);
}
